package leetbook.sort_search;

import java.util.Arrays;
import java.util.Comparator;

public class Solution179 {

    public static void main(String[] args) {

        int[] nums = {0,0,0};
        System.out.println(new Solution179().largestNumber(nums));
    }

    public String largestNumber(int[] nums) {
        Integer[] integers = new Integer[nums.length];
        for (int i = 0; i < nums.length; i++) {
            integers[i] = Integer.valueOf(nums[i]);
        }

        Arrays.sort(integers,(o1, o2) -> {
            String s1 = String.valueOf(o1);
            String s2 = String.valueOf(o2);
            return -(s1+s2).compareTo(s2+s1);
        });

        //字符串全0 <=> 字符串以0开头
        if(integers[0].equals(0)) return "0";

        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < integers.length; i++) {
            sb.append(integers[i].toString());
        }

        return sb.toString();
    }

}
